/**
 * zmn产品模块-产品列表
 * @author tanghongjun
 * @since 2018/10/18
 */
layui.extend({
    zmnExportUtil: '{/}/static/js/zmn.excel.util'
}).define(['index', 'form', 'table', 'laypage', 'layedit','zmnExportUtil'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var table = layui.table;
    var laypage = layui.laypage;
    var layedit = layui.layedit;
    let zmnExportUtil =layui.zmnExportUtil;
    table.init('zmn-table', {
        toolbar: "#zmn-table-tool",
        page: true,
        limit: json.pageSize,
        height: 'full-110',
        done: function () {
            $("div[lay-event='LAYTABLE_EXPORT']").attr('lay-event', 'CUSTOM_EXPORT');
        },
    });
    laypage.render(layui.$.extend({limits:[10, 20, 30, 40, 50,100]},zmnPage.laypageOptions(json)));

    let ids = new Array();

    // 选择（全选或单选）
    table.on("checkbox(zmn-table)", function (obj) {
        ids = table.checkStatus('zmn-table').data.map((item) => item.questionId);
    });

    // 启用/停用
    table.on("toolbar(zmn-table)", function (obj) {
        //导出excel
        if(obj.event=='CUSTOM_EXPORT'){
            return zmnExportUtil.doExportExcel('zmn-table','回访问题');
        }
        //启用停用
        if (obj.event != "start" && obj.event != "stop") {
            return false;
        }
        if (ids.length === 0) {
            return layer.alert("请选择至少1条数据！");
        }
        zmnPage.layStartStop3(obj, "/orderconfig/returnvisit/question/updateStatus.action", ids.join(","),"确定停用？停用后，将不会出现这个回访问题");
    });

    // 修改排序和首字母
    table.on("edit(zmn-table)", function (obj) {
        if(obj.field=='sort'){
            zmnPage.laySortPositiveInteger(obj.value,"/orderconfig/returnvisit/question/updateSort.action",obj.data.questionId,100000,0)
        }else if(obj.field=='firstLetter'){
            zmnPage.layFirstLetter(obj.value,"/orderconfig/returnvisit/question/updateFirstLetter.action",obj.data.questionId,3,1000);
        }

    });

    //对外暴露的接口
    exports('orderconfig_returnvisitquestion_list', {});
});

/**
 * 描述: 新增/修改回访问题
 **/
function addEditReturnVisitQuestion(id){
    if (id == ""){
        zmnLayUtil.openIframeCustom(layer, "/orderconfig/returnvisit/question/detail.action", {title: "新增", shade: 0.8, area:["700px", "480px"]});
    } else {
        zmnLayUtil.openIframeCustom(layer, "/orderconfig/returnvisit/question/detail.action?id="+id, {title: "修改", shade: 0.8, area:["700px", "480px"]});
    }
}
